@extends('adminDialog')
@section('content')
    <form action="{{url('admin/categories/update/'.$model->id)}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table">
            <table width="100%">
                <tbody>
                <tr>
                    <th><label for="parent_id">上级分类 <span class="red">*</span></label></th>
                    <td>
                        <select name="parent_id" id="parent_id">
                            <option @if($model->parent_id == 0) selected="selected" @endif value="0">顶级分类</option>
                            @foreach($parent as $item)
                                <option @if($model->parent_id == $item->id) selected="selected" @endif value="{{$item->id}}">{{$item->name}}</option>
                            @endforeach
                        </select>
                    </td>
                </tr>
                <tr>
                    <th><label for="name">分类名称 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_2" value="{{$model->name}}"/>
                    </td>
                </tr>

                <tr>
                    <th><label for="icon">分类图标 </label></th>
                    <td>
                        <input type="hidden" name="icon" id="icon" value="{{intval($model->icon)}}"/>
                        <span id="upload_btn" class="cc"><img src="{{url('/img/category-'.intval($model->icon).'/50-50')}}"</span>
                        <div class="cc gray">建议 50px * 50px</div>
                    </td>
                </tr>

                <tr>
                    <th><label for="agent_fee">代理提点 <span class="red">*</span></label></th>
                    <td>
                        <input type="number" name="agent_fee" id="agent_fee" class="input length_1" value="{{$model->agent_fee}}"/>%
                    </td>
                </tr>

                <!--
                <tr>
                    <th><label for="online_pay_fee">线上支付返利 <span class="red">*</span></label></th>
                    <td>
                        <input type="number" name="online_pay_fee" id="online_pay_fee" class="input length_1" value="{{$model->online_pay_fee}}"/>%
                    </td>
                </tr>

                <tr>
                    <th><label for="offline_pay_fee">线下支付返利 <span class="red">*</span></label></th>
                    <td>
                        <input type="number" name="offline_pay_fee" id="offline_pay_fee" class="input length_1" value="{{$model->offline_pay_fee}}"/>%
                    </td>
                </tr>

                <tr>
                    <th><label for="coin_pay_fee">金币支付返利 <span class="red">*</span></label></th>
                    <td>
                        <input type="number" name="coin_pay_fee" id="coin_pay_fee" class="input length_1" value="{{$model->coin_pay_fee}}"/>%
                    </td>
                </tr>
                -->
                <tr>
                    <th><label for="sort">显示排序 <span class="red">*</span></label></th>
                    <td>
                        <input type="number" name="sort" id="sort" class="input length_2" value="{{$model->sort}}"/>
                    </td>
                </tr>

                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style>
        .body_none {width: 320px;}
        #upload_btn {cursor:pointer; display: inline-block;}
    </style>
@stop

@section('js')
    @parent
    <script src="{{asset('/js/plupload/plupload.full.min.js')}}"></script>
    <script>
        var uploader = new plupload.Uploader({
            browse_button : 'upload_btn',
            url : '{{url('/upimg')}}',
            flash_swf_url : '{{asset('/js/plupload/Moxie.swf')}}',
            silverlight_xap_url: '{{asset('/js/plupload/Moxie.xap')}}',
            filters : {
                mime_types : [
                    {title: '图片文件', extensions: "jpg,gif,png"}
                ]
            },
            multi_selection : false,
            file_data_name  : 'file',
            multipart_params: {'_token': GV.TOKEN, 'dir': 'category'}
        });
        uploader.init();

        uploader.bind('Error', function (uploader, errObject) {
            Wind.dialog.alert(errObject.message);
        });

        uploader.bind('FilesAdded', function () {
            uploader.start();
        });
        uploader.bind('FileUploaded', function (uploader, file, responseObj) {
            var ret = $.parseJSON(responseObj.response);
            if (! ret.id)
                Wind.dialog.alert(ret.message);
            else {
                $('#icon').val(ret.id);
                $('#upload_btn').find('img').attr('src', '{!!url("img/category-' + ret.id + '/50-50")!!}');
            }
        });
    </script>
@stop